package com.btks.mapreduce.writable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author cheng-qiang
 * @date 2022年11月01日15:10
 */
public class FlowDriver {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        job.setJarByClass(FlowDriver.class);

        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        job.setMapOutputKeyClass(FlowBean.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        // 指定自定义分区器
        job.setPartitionerClass(ProvincePartitioner.class);
        // 指定相应数量的ReduceTask
        job.setNumReduceTasks(5);

        FileInputFormat.setInputPaths(job, new Path("E:\\hadoop\\input\\writable"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\hadoop\\output\\writableFlow"));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);

    }
}
